/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaProTableColumns, MaProTableExpose } from '@mineadmin/pro-table'
import type { UseDialogExpose } from '@/hooks/useDialog.ts'

import defaultAvatar from '@/assets/images/defaultAvatar.jpg'
import { ElTag } from 'element-plus'
import { useMessage } from '@/hooks/useMessage.ts'
import { ResultCode } from '@/utils/ResultCode.ts'
import hasAuth from '@/utils/permission/hasAuth.ts'
import { deleteByIds } from '$/attractions/guangbo/api/guangboPlans.ts'

export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t: any): MaProTableColumns[] {
  const msg = useMessage()

  return [
    { type: 'selection', showOverflowTooltip: false, label: () => t('crud.selection') },
    { label: '音频文件路径', prop: 'content_audio_file', multiple: false, cellRender: ({ row }) => {                       
    return (
        <el-link onClick={() => row?.content_audio_file ? window.open(row?.content_audio_file):msg.info("无文件") } target="_blank"><icon-view />查看文件</el-link>
    )
} },
    { label: '开始时间，控制播放时间段', prop: 'start_time' },
    { label: '结束时间，控制播放时间段', prop: 'end_time' },
    { label: '执行日期，逗号间隔，按不同重复类型', prop: 'execution_day' },
    { label: '重复类型：1-不重复，2-每天，3-每周，4-每月', prop: 'repeat_type' },
    { label: '重复间隔（分钟）', prop: 'repeat_interval' },
    { label: '重复次数', prop: 'repeat_count' },
    { label: '触发事件ID', prop: 'trigger_event' },
    { label: '音量', prop: 'volume_day' },
    { label: '最后执行时间', prop: 'last_execution_time', mode: 'date', showTime: true },
    { label: '已执行次数', prop: 'execution_count' },
    { type: 'operation', label: () => t('crud.operation'), operationConfigure: { actions: [
    { name: 'edit', icon: 'material-symbols:person-edit', show: ({ row }) => hasAuth('attraction/guangbo:guangboPlans:update'), text: () => t('crud.edit'), onClick: ({ row }) => {
              dialog.setTitle(t('crud.edit'))
              dialog.open({ formType: 'edit', data: row })
            } },
    { name: 'del', icon: 'mdi:delete', text: () => t('crud.delete'), show: ({ row }) => hasAuth('attraction/guangbo:guangboPlans:delete'), onClick: ({ row }, proxy: MaProTableExpose) => {
              msg.delConfirm(t('crud.delDataMessage')).then(async () => {
                const response = await deleteByIds([row.id])
                if (response.code === ResultCode.SUCCESS) {
                  msg.success(t('crud.delSuccess'))
                  proxy.refresh()
                }
              })
            } },
  ] } },
  ]
}
